package com.sc.lindada.controller;

import com.sc.lindada.annotation.AuthCheck;
import com.sc.lindada.common.BaseResponse;
import com.sc.lindada.common.ErrorCode;
import com.sc.lindada.common.ResultUtils;
import com.sc.lindada.constant.UserConstant;
import com.sc.lindada.exception.ThrowUtils;
import com.sc.lindada.mapper.UserAnswerMapper;
import com.sc.lindada.model.dto.statistic.AppAnswerCountDTO;
import com.sc.lindada.model.dto.statistic.AppAnswerResultCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * App统计分析接口
 *
 * @author 林笙
 */
@RestController
@RequestMapping("/app/statistic")
@Slf4j
public class AppStatisticController {

    @Resource
    private UserAnswerMapper userAnswerMapper;

    /**
     * 获取热门应用答题数量统计
     * @return
     */
    @GetMapping("/answer_count")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<List<AppAnswerCountDTO>> getAppAnswerCount() {
        return ResultUtils.success(userAnswerMapper.doAppAnswerCount());
    }

    /**
     * 某个App回答分布统计
     * @param appId
     * @return
     */
    @GetMapping("/answer_result_count")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<List<AppAnswerResultCountDTO>> getAppAnswerResultCount(Long appId) {
        ThrowUtils.throwIf(appId==null || appId <= 0 , ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(userAnswerMapper.doAppAnswerResultCount(appId));
    }
}
